# 本地预警服务

import config
import mod_relay


# 是否断电预警
is_warning_power_off = False
power_off_timestamp = 0

# 是否电流异常预警
is_warning_current_abnormal = False
current_abnormal_timestamp = 0
current_abnormal_max_time = 0

# 设置参数
power_off_check = 0
current_check = 0
current_max_time = 0
current_warning_value = 0


class WarningService:
    def __init__(self):
        warnign_config = config.get_config("warning")
        self.power_off_check = warnign_config.get("power_off_check", 0)
        self.current_check = warnign_config.get("current_check", 0)
        self.current_max_time = warnign_config.get("current_max_time", 5)
        self.current_warning_value = warnign_config.get("current_warning_value", 80)

    def check_warning(self):
        if self.power_off_check:
            # 断电预警的逻辑
            self.power_off_check()

        if self.current_check:
            # 电流预警的逻辑
            self.current_check()

        # 数据采集的逻辑
        pass

    def power_off_check(self,data):
        mod_relay.relay_ctl(1, 0)
        

    def current_check(self):
        # 电流预警的逻辑
        pass


runtime_warning_service = WarningService()
